use mysql;
use serde::{Deserialize, Serialize};
use std::sync::{Arc, Mutex};
#[derive(Deserialize, Serialize, Debug)]
pub struct DbConfig {
    host: String,
    port: u16,
    db: String,
    user: String,
    pass: String,
}
#[derive(Debug, Clone)]
pub struct DatabaseState {
    pub pool: mysql::Pool,
}
pub fn init(config: &DbConfig) -> Arc<Mutex<DatabaseState>> {
    let mut builder = mysql::OptsBuilder::new();
    builder = builder.ip_or_hostname(Some(&config.host)).tcp_port(config.port).db_name(Some(&config.db)).user(Some(&config.user)).pass(Some(&config.pass));
    let pool = mysql::Pool::new(builder).unwrap();
    Arc::new(Mutex::new(DatabaseState { pool }))
}
